package com.wyvoid.forum.web.action.user;

import net.sourceforge.stripes.action.*;
import net.sourceforge.stripes.integration.spring.SpringBean;
import com.wyvoid.forum.web.action.BaseAction;
import com.wyvoid.forum.web.tag.ForumFunctions;
import com.wyvoid.forum.domain.User;
import com.wyvoid.forum.domain.SessionUser;
import com.wyvoid.forum.domain.UserProfile;
import com.wyvoid.forum.service.IUserService;
import com.wyvoid.core.persistent.Pagination;
import com.wyvoid.core.persistent.hibernate.HibernatePage;
import org.apache.commons.lang.StringUtils;


/**
 * Created by IntelliJ IDEA.
 * User: qj
 * Date: 2007-6-25
 * Time: 21:17:07
 * To change this template use File | Settings | File Templates.
 */
@UrlBinding("/user/member.do")
public class UserAction extends BaseAction {
    private User user;
    private UserProfile userProfile;
    private long userId;
    private IUserService userService;
    private HibernatePage myUserList;

    public IUserService getUserService() {
        return userService;
    }

    public HibernatePage getMyUserList() {
        return myUserList;
    }

    @SpringBean
    public void setUserService(IUserService userService) {
        this.userService = userService;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }


    public UserProfile getUserProfile() {
        return userProfile;
    }

    public void setUserProfile(UserProfile userProfile) {
        this.userProfile = userProfile;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    @DontValidate
    @DefaultHandler
    public Resolution member() {
//        SessionUser user = getContext().getUser();
//         if(user!=null){
        Pagination pagination=new Pagination();
        pagination.setPageNumber(1);
        pagination.setPageSize(10);
        String strUserName=context.getRequest().getParameter("searchmem");
        System.out.println("strUserName===="+strUserName);
        if(strUserName==null||strUserName.equals("")){
        String strUserKey = context.getRequest().getParameter("userkey");
        if(strUserKey==null||strUserKey.equals("")){
            myUserList = userService.getAllUser(pagination);
            return getBBSResolution("user/userList");
        }else{
            myUserList = userService.getSearchUser(strUserKey,pagination);
            return getBBSResolution("user/userList");
        }}else{
            myUserList = userService.getSearchUserName(strUserName,pagination);
            return getBBSResolution("user/userList");
        }
//        }else{
//                   return null;
//        }
    }

    @DontValidate
    public Resolution userData(){
        user=userService.getUser(userId);
        userProfile = userService.getUserProfile(userId);
        return getBBSResolution("user/userData");   
    }
}
